I am using Python in order to query the pagerduty API for historic incidents. I have no issues receiving a response containing incidents, however, paging is not functioning as expected.
For testing purposes I have limited the number of cases returned & set the limit 2. Below it is clear each page is returns 1 new case when 2 new cases are expected. I can set the limit to 5 or 100 & a single new case will be returned, followed by the previously returned cases -1. Is this a known issue? Is it possible to workaround the issues in some way?
Python code:
import requests
import json
import time
def get_incidents(offset):
url = âhttps://api.pagerduty.com/incidents?since=2018-05-18%2000%3A00&until=2018-05-19%2000%3A00&statuses[]=triggered&statuses[]=acknowledged&statuses[]=resolved&service_ids[]=<some_service>&time_zone=America%2FChicago&limit=2&total=true&offset=â+str(offset)
headers = {âAcceptâ: âapplication/vnd.pagerduty+json;version=2â, âAuthorizationâ: âToken token=<some_token>â}
response = requests.get(url, headers=headers)
page = response.json()[âmoreâ]
#print response.json()
incidents = response.json()[âincidentsâ]
for incident in incidents:
#print â%s,%s,%s,%sâ % (incident[âcreated_atâ], incident[âincident_numberâ] , incident[âdescriptionâ], incident[âhtml_urlâ])
print â%s,%sâ % (incident[âcreated_atâ], incident[âincident_numberâ])
return page
offset = 0
page = get_incidents(offset)
while page == True:
print âOffset:â,str(offset)
print âMore:â,str(page)
offset = offset + 1
time.sleep(4)
page = get_incidents(offset)
else:
print page
exit
Results:
2018-05-18T00:16:37-05:00,360080
2018-05-18T02:32:23-05:00,360110
Offset: 0
More: True
2018-05-18T02:32:23-05:00,360110
2018-05-18T10:04:27-05:00,360242
Offset: 1
More: True
2018-05-18T10:04:27-05:00,360242
2018-05-18T10:04:33-05:00,360243
Offset: 2
More: True
2018-05-18T10:04:33-05:00,360243
2018-05-18T10:39:13-05:00,360259
Offset: 3
More: True
2018-05-18T10:39:13-05:00,360259
2018-05-18T11:07:21-05:00,360267
Offset: 4
More: True
2018-05-18T11:07:21-05:00,360267
2018-05-18T12:04:38-05:00,360286
Offset: 5
More: True
2018-05-18T12:04:38-05:00,360286
2018-05-18T12:35:47-05:00,360305
Offset: 6
More: True
2018-05-18T12:35:47-05:00,360305
2018-05-18T12:40:52-05:00,360307
Offset: 7
More: True
2018-05-18T12:40:52-05:00,360307
2018-05-18T14:15:11-05:00,360362
Offset: 8
More: True
2018-05-18T14:15:11-05:00,360362
2018-05-18T16:43:05-05:00,360431
Offset: 9
More: True
2018-05-18T16:43:05-05:00,360431
2018-05-18T16:44:53-05:00,360432
False